package link.anyauto.dtbinding.widgets;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.ObservableArrayList;

import java.util.List;

import link.anyauto.dtbinding.BR;
import link.anyauto.dtbinding.R;
import link.anyauto.dtbinding.util.CompareUtil;
import me.tatarka.bindingcollectionadapter.ItemView;

/**
 * Created by LYQ on 2016/7/26.
 */
public class WidgetsVM extends BaseObservable{
    public final List<Item> items = new ObservableArrayList<>();
    public final ItemView itemView = ItemView.of(BR.item, R.layout.widgets_item);
    public final ItemView dropDown = ItemView.of(BR.item, R.layout.drop_down_item);

    public String baiduIcon = "https://www.baidu.com/img/bd_logo1.png";
    public int petRes = R.drawable.pet;

    boolean radio[] = new boolean[3];
    boolean check[] = new boolean[3];
    int progress;
    String text;

    @Bindable
    public boolean[] getRadio() {
        return radio;
    }

    public void setRadio(boolean radio, int pos) {
        if(radio && this.radio[pos] != radio) {
            for (int i=0; i<this.radio.length; i++) {
                this.radio[i] = false;
            }
            this.radio[pos] = radio;
            notifyPropertyChanged(BR.radio);
        }
    }

    @Bindable
    public boolean[] getCheck() {
        return check;
    }

    public void setCheck(boolean check, int pos) {
        if(this.check[pos] != check) {
            this.check[pos] = check;
            notifyPropertyChanged(BR.check);
        }
    }

    @Bindable
    public int getProgress() {
        return progress;
    }

    public void setProgress(int progress) {
        if(this.progress != progress) {
            this.progress = progress;
            notifyPropertyChanged(BR.progress);
        }
    }

    @Bindable
    public String getText() {
        return text;
    }

    public void setText(String text) {
        if(!CompareUtil.equals(this.text, text)) {
            this.text = text;
            notifyPropertyChanged(BR.text);
        }
    }
}
